home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / BZIP2 / 980316 / bzip / Patch < prev    next >
Text File  |  1998-03-16  |  24KB  |  757 lines

  1. --- bzip2.c    Fri Aug 29 23:32:15 1997
  2. +++ bzip2.acorn    Fri Mar 13 15:25:45 1998
  3. @@ -1,4 +1,3 @@
  4. -
  5.  /*-----------------------------------------------------------*/
  6.  /*--- A block-sorting, lossless compressor        bzip2.c ---*/
  7.  /*-----------------------------------------------------------*/
  8. @@ -94,16 +93,20 @@
  9.    Generic 32-bit Unix.
  10.    Also works on 64-bit Unix boxes.
  11.  --*/
  12. -#define BZ_UNIX      1
  13. +#define BZ_UNIX        0
  14.  
  15.  /*--
  16.    Win32, as seen by Jacob Navia's excellent
  17.    port of (Chris Fraser & David Hanson)'s excellent
  18.    lcc compiler.
  19.  --*/
  20. -#define BZ_LCCWIN32  0
  21. +#define BZ_LCCWIN32    0
  22.  
  23. +/*--
  24. +  Acorn's RISC OS (currently requires unixlib & gcc)
  25. +--*/
  26.  
  27. +#define BZ_RISCOS    1
  28.  
  29.  /*---------------------------------------------*/
  30.  /*--
  31. @@ -225,6 +228,44 @@
  32.  
  33.  #endif
  34.  
  35. +#if BZ_RISCOS
  36. +   #define BZ_FILETYPE 0x16E
  37. +
  38. +   #include <sys/types.h>
  39. +   #include <stdio.h>        /* required by tmpnam() */
  40. +   #include <sys/os.h>        /* required by os_file() */
  41. +   #include <utime.h>
  42. +   #include <unistd.h>        /* can i narrow this down & remove it? */
  43. +   #include <malloc.h>
  44. +   #include <sys/stat.h>
  45. +   #include <sys/times.h>
  46. +
  47. +
  48. +   #define Int32   int
  49. +   #define UInt32  unsigned int
  50. +   #define Char    char
  51. +   #define UChar   unsigned char
  52. +   #define Int16   short
  53. +   #define UInt16  unsigned short
  54. +
  55. +   #define PATH_SEP    '.'
  56. +   #define MY_LSTAT    lstat
  57. +   #define MY_S_IFREG  S_ISREG
  58. +   #define MY_STAT     stat
  59. +
  60. +   #define APPEND_FILESPEC(root, name) \
  61. +      root=snocString((root), (name))
  62. +
  63. +   #define SET_BINARY_MODE(fd) /**/
  64. +
  65. +   /*--
  66. +      You should try very hard to persuade your C compiler
  67. +      to inline the bits marked INLINE.  Otherwise bzip2 will
  68. +      run rather slowly.  gcc version 2.x is recommended.
  69. +   --*/
  70. +   #define INLINE   inline
  71. +   #define NORETURN __attribute__ ((noreturn))
  72. +#endif
  73.  
  74.  /*---------------------------------------------*/
  75.  /*--
  76. @@ -408,7 +449,7 @@
  77.  --*/
  78.  UChar    *block;    /*-- compress   --*/
  79.  UInt16   *quadrant; /*-- compress   --*/
  80. -Int32    *zptr;     /*-- compress   --*/ 
  81. +Int32    *zptr;     /*-- compress   --*/
  82.  UInt16   *szptr;    /*-- overlays zptr ---*/
  83.  Int32    *ftab;     /*-- compress   --*/
  84.  
  85. @@ -448,7 +489,7 @@
  86.  
  87.  /*--
  88.    Used when sorting.  If too many long comparisons
  89. -  happen, we stop sorting, randomise the block 
  90. +  happen, we stop sorting, randomise the block
  91.    slightly, and try again.
  92.  --*/
  93.  
  94. @@ -821,7 +862,7 @@
  95.  
  96.  
  97.  /*---------------------------------------------*/
  98. -void hbMakeCodeLengths ( UChar *len, 
  99. +void hbMakeCodeLengths ( UChar *len,
  100.                           Int32 *freq,
  101.                           Int32 alphaSize,
  102.                           Int32 maxLen )
  103. @@ -835,7 +876,7 @@
  104.  
  105.     Int32 heap   [ MAX_ALPHA_SIZE + 2 ];
  106.     Int32 weight [ MAX_ALPHA_SIZE * 2 ];
  107. -   Int32 parent [ MAX_ALPHA_SIZE * 2 ]; 
  108. +   Int32 parent [ MAX_ALPHA_SIZE * 2 ];
  109.  
  110.     for (i = 0; i < alphaSize; i++)
  111.        weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
  112. @@ -855,9 +896,9 @@
  113.           heap[nHeap] = i;
  114.           UPHEAP(nHeap);
  115.        }
  116. -      if (!(nHeap < (MAX_ALPHA_SIZE+2))) 
  117. +      if (!(nHeap < (MAX_ALPHA_SIZE+2)))
  118.           panic ( "hbMakeCodeLengths(1)" );
  119. -   
  120. +
  121.        while (nHeap > 1) {
  122.           n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
  123.           n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
  124. @@ -880,7 +921,7 @@
  125.           len[i-1] = j;
  126.           if (j > maxLen) tooLong = True;
  127.        }
  128. -      
  129. +
  130.        if (! tooLong) break;
  131.  
  132.        for (i = 1; i < alphaSize; i++) {
  133. @@ -1015,7 +1056,7 @@
  134.        The back end needs a place to store the MTF values
  135.        whilst it calculates the coding tables.  We could
  136.        put them in the zptr array.  However, these values
  137. -      will fit in a short, so we overlay szptr at the 
  138. +      will fit in a short, so we overlay szptr at the
  139.        start of zptr, in the hope of reducing the number
  140.        of cache misses induced by the multiple traversals
  141.        of the MTF values when calculating coding tables.
  142. @@ -1109,7 +1150,7 @@
  143.     wr = 0;
  144.     zPend = 0;
  145.     for (i = 0; i < nInUse; i++) yy[i] = (UChar) i;
  146. -   
  147. +
  148.  
  149.     for (i = 0; i <= last; i++) {
  150.        UChar ll_i;
  151. @@ -1195,8 +1236,8 @@
  152.     Int32  fave[N_GROUPS];
  153.  
  154.     if (verbosity >= 3)
  155. -      fprintf ( stderr, 
  156. -                "      %d in block, %d after MTF & 1-2 coding, %d+2 syms in use\n", 
  157. +      fprintf ( stderr,
  158. +                "      %d in block, %d after MTF & 1-2 coding, %d+2 syms in use\n",
  159.                  last+1, nMTF, nInUse );
  160.  
  161.     alphaSize = nInUse+2;
  162. @@ -1211,7 +1252,7 @@
  163.                     nGroups = 6;
  164.  
  165.     /*--- Generate an initial set of coding tables ---*/
  166. -   { 
  167. +   {
  168.        Int32 nPart, remF, tFreq, aFreq;
  169.  
  170.        nPart = nGroups;
  171. @@ -1226,31 +1267,31 @@
  172.              aFreq += mtfFreq[ge];
  173.           }
  174.  
  175. -         if (ge > gs 
  176. -             && nPart != nGroups && nPart != 1 
  177. +         if (ge > gs
  178. +             && nPart != nGroups && nPart != 1
  179.               && ((nGroups-nPart) % 2 == 1)) {
  180.              aFreq -= mtfFreq[ge];
  181.              ge--;
  182.           }
  183.  
  184.           if (verbosity >= 3)
  185. -            fprintf ( stderr, 
  186. +            fprintf ( stderr,
  187.                        "      initial group %d, [%d .. %d], has %d syms (%4.1f%%)\n",
  188. -                              nPart, gs, ge, aFreq, 
  189. +                              nPart, gs, ge, aFreq,
  190.                                (100.0 * (float)aFreq) / (float)nMTF );
  191. +
  192.           for (v = 0; v < alphaSize; v++)
  193. -            if (v >= gs && v <= ge) 
  194. +            if (v >= gs && v <= ge)
  195.                 len[nPart-1][v] = LESSER_ICOST; else
  196.                 len[nPart-1][v] = GREATER_ICOST;
  197. +
  198.           nPart--;
  199.           gs = ge+1;
  200.           remF -= aFreq;
  201.        }
  202.     }
  203.  
  204. -   /*--- 
  205. +   /*---
  206.        Iterate up to N_ITERS times to improve the tables.
  207.     ---*/
  208.     for (iter = 0; iter < N_ITERS; iter++) {
  209. @@ -1268,10 +1309,10 @@
  210.  
  211.           /*--- Set group start & end marks. --*/
  212.           if (gs >= nMTF) break;
  213. -         ge = gs + G_SIZE - 1; 
  214. +         ge = gs + G_SIZE - 1;
  215.           if (ge >= nMTF) ge = nMTF-1;
  216.  
  217. -         /*-- 
  218. +         /*--
  219.              Calculate the cost of this group as coded
  220.              by each of the coding tables.
  221.           --*/
  222. @@ -1280,7 +1321,7 @@
  223.           if (nGroups == 6) {
  224.              register UInt16 cost0, cost1, cost2, cost3, cost4, cost5;
  225.              cost0 = cost1 = cost2 = cost3 = cost4 = cost5 = 0;
  226. -            for (i = gs; i <= ge; i++) { 
  227. +            for (i = gs; i <= ge; i++) {
  228.                 UInt16 icv = szptr[i];
  229.                 cost0 += len[0][icv];
  230.                 cost1 += len[1][icv];
  231. @@ -1292,13 +1333,13 @@
  232.              cost[0] = cost0; cost[1] = cost1; cost[2] = cost2;
  233.              cost[3] = cost3; cost[4] = cost4; cost[5] = cost5;
  234.           } else {
  235. -            for (i = gs; i <= ge; i++) { 
  236. +            for (i = gs; i <= ge; i++) {
  237.                 UInt16 icv = szptr[i];
  238.                 for (t = 0; t < nGroups; t++) cost[t] += len[t][icv];
  239.              }
  240.           }
  241. -         /*-- 
  242. +
  243. +         /*--
  244.              Find the coding table which is best for this group,
  245.              and record its identity in the selector table.
  246.           --*/
  247. @@ -1310,7 +1351,7 @@
  248.           selector[nSelectors] = bt;
  249.           nSelectors++;
  250.  
  251. -         /*-- 
  252. +         /*--
  253.              Increment the symbol frequencies for the selected table.
  254.            --*/
  255.           for (i = gs; i <= ge; i++)
  256. @@ -1319,8 +1360,8 @@
  257.           gs = ge+1;
  258.        }
  259.        if (verbosity >= 3) {
  260. -         fprintf ( stderr, 
  261. -                   "      pass %d: size is %d, grp uses are ", 
  262. +         fprintf ( stderr,
  263. +                   "      pass %d: size is %d, grp uses are ",
  264.                     iter+1, totc/8 );
  265.           for (t = 0; t < nGroups; t++)
  266.              fprintf ( stderr, "%d ", fave[t] );
  267. @@ -1370,19 +1411,19 @@
  268.        }
  269.        if (maxLen > 20) panic ( "sendMTFValues(3)" );
  270.        if (minLen < 1)  panic ( "sendMTFValues(4)" );
  271. -      hbAssignCodes ( &code[t][0], &len[t][0], 
  272. +      hbAssignCodes ( &code[t][0], &len[t][0],
  273.                        minLen, maxLen, alphaSize );
  274.     }
  275.  
  276.     /*--- Transmit the mapping table. ---*/
  277. -   { 
  278. +   {
  279.        Bool inUse16[16];
  280.        for (i = 0; i < 16; i++) {
  281.            inUse16[i] = False;
  282.            for (j = 0; j < 16; j++)
  283.               if (inUse[i * 16 + j]) inUse16[i] = True;
  284.        }
  285. -     
  286. +
  287.        nBytes = bytesOut;
  288.        for (i = 0; i < 16; i++)
  289.           if (inUse16[i]) bsW(1,1); else bsW(1,0);
  290. @@ -1392,7 +1433,7 @@
  291.              for (j = 0; j < 16; j++)
  292.                 if (inUse[i * 16 + j]) bsW(1,1); else bsW(1,0);
  293.  
  294. -      if (verbosity >= 3) 
  295. +      if (verbosity >= 3)
  296.           fprintf ( stderr, "      bytes: mapping %d, ", bytesOut-nBytes );
  297.     }
  298.  
  299. @@ -1400,7 +1441,7 @@
  300.     nBytes = bytesOut;
  301.     bsW ( 3, nGroups );
  302.     bsW ( 15, nSelectors );
  303. -   for (i = 0; i < nSelectors; i++) { 
  304. +   for (i = 0; i < nSelectors; i++) {
  305.        for (j = 0; j < selectorMtf[i]; j++) bsW(1,1);
  306.        bsW(1,0);
  307.     }
  308. @@ -1429,9 +1470,9 @@
  309.     gs = 0;
  310.     while (True) {
  311.        if (gs >= nMTF) break;
  312. -      ge = gs + G_SIZE - 1; 
  313. +      ge = gs + G_SIZE - 1;
  314.        if (ge >= nMTF) ge = nMTF-1;
  315. -      for (i = gs; i <= ge; i++) { 
  316. +      for (i = gs; i <= ge; i++) {
  317.           #if DEBUG
  318.              assert (selector[selCtr] < nGroups);
  319.           #endif
  320. @@ -1467,8 +1508,8 @@
  321.  
  322.     /*--- Receive the mapping table ---*/
  323.     for (i = 0; i < 16; i++)
  324. -      if (bsR(1) == 1) 
  325. -         inUse16[i] = True; else 
  326. +      if (bsR(1) == 1)
  327. +         inUse16[i] = True; else
  328.           inUse16[i] = False;
  329.  
  330.     for (i = 0; i < 256; i++) inUse[i] = False;
  331. @@ -1494,7 +1535,7 @@
  332.     {
  333.        UChar pos[N_GROUPS], tmp, v;
  334.        for (v = 0; v < nGroups; v++) pos[v] = v;
  335. -   
  336. +
  337.        for (i = 0; i < nSelectors; i++) {
  338.           v = selectorMtf[i];
  339.           tmp = pos[v];
  340. @@ -1523,7 +1564,7 @@
  341.           if (len[t][i] > maxLen) maxLen = len[t][i];
  342.           if (len[t][i] < minLen) minLen = len[t][i];
  343.        }
  344. -      hbCreateDecodeTables ( 
  345. +      hbCreateDecodeTables (
  346.           &limit[t][0], &base[t][0], &perm[t][0], &len[t][0],
  347.           minLen, maxLen, alphaSize
  348.        );
  349. @@ -1603,7 +1644,7 @@
  350.  
  351.           if (smallMode)
  352.              while (s > 0) {
  353. -               last++; 
  354. +               last++;
  355.                 ll16[last] = ch;
  356.                 s--;
  357.              }
  358. @@ -1782,7 +1823,7 @@
  359.  
  360.     for (; hp >= 0; hp--) {
  361.        h = incs[hp];
  362. -      if (verbosity >= 5) 
  363. +      if (verbosity >= 5)
  364.           fprintf ( stderr, "          shell increment %d\n", h );
  365.  
  366.        i = lo + h;
  367. @@ -2154,58 +2195,58 @@
  368.  /*---------------------------------------------------*/
  369.  
  370.  /*---------------------------------------------*/
  371. -Int32 rNums[512] = { 
  372. -   619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 
  373. -   985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 
  374. -   733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 
  375. -   419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 
  376. -   878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 
  377. -   862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 
  378. -   150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 
  379. -   170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 
  380. -   73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 
  381. -   909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 
  382. -   641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 
  383. -   161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 
  384. -   382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 
  385. -   98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 
  386. -   227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 
  387. -   469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 
  388. -   184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 
  389. -   715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 
  390. -   951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 
  391. -   652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 
  392. -   645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 
  393. -   609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 
  394. -   653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 
  395. -   411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 
  396. -   170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 
  397. -   857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 
  398. -   669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 
  399. -   944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 
  400. -   344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 
  401. -   897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 
  402. -   433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 
  403. -   686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 
  404. -   946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 
  405. -   978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 
  406. -   680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 
  407. -   707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 
  408. -   297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 
  409. -   134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 
  410. -   343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 
  411. -   140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 
  412. -   170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 
  413. -   369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 
  414. -   804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 
  415. -   896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 
  416. -   661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 
  417. -   768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 
  418. -   61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 
  419. -   372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 
  420. -   780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 
  421. -   920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 
  422. -   645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 
  423. +Int32 rNums[512] = {
  424. +   619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
  425. +   985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
  426. +   733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
  427. +   419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
  428. +   878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
  429. +   862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
  430. +   150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
  431. +   170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
  432. +   73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
  433. +   909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
  434. +   641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
  435. +   161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
  436. +   382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
  437. +   98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
  438. +   227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
  439. +   469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
  440. +   184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
  441. +   715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
  442. +   951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
  443. +   652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
  444. +   645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
  445. +   609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
  446. +   653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
  447. +   411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
  448. +   170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
  449. +   857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
  450. +   669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
  451. +   944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
  452. +   344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
  453. +   897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
  454. +   433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
  455. +   686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
  456. +   946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
  457. +   978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
  458. +   680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
  459. +   707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
  460. +   297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
  461. +   134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
  462. +   343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
  463. +   140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
  464. +   170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
  465. +   369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
  466. +   804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
  467. +   896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
  468. +   661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
  469. +   768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
  470. +   61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
  471. +   372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
  472. +   780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
  473. +   920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
  474. +   645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
  475.     936, 638
  476.  };
  477.  
  478. @@ -2401,12 +2442,12 @@
  479.                 ch2 ^= (UInt32)RAND_MASK;
  480.              }
  481.              i2++;
  482. -   
  483. +
  484.              if (dst)
  485.                 retVal = putc ( ch2, dst );
  486. -   
  487. +
  488.              UPDATE_CRC ( localCrc, (UChar)ch2 );
  489. -   
  490. +
  491.              if (ch2 != chPrev) {
  492.                 count = 1;
  493.              } else {
  494. @@ -2504,10 +2545,10 @@
  495.              RAND_UPD_MASK;
  496.              ch2 ^= (UInt32)RAND_MASK;
  497.              i2++;
  498. -   
  499. +
  500.              retVal = putc ( ch2, dst );
  501.              UPDATE_CRC ( localCrc, (UChar)ch2 );
  502. -   
  503. +
  504.              if (ch2 != chPrev) {
  505.                 count = 1;
  506.              } else {
  507. @@ -2534,10 +2575,10 @@
  508.              chPrev = ch2;
  509.              GET_FAST(ch2);
  510.              i2++;
  511. -   
  512. +
  513.              retVal = putc ( ch2, dst );
  514.              UPDATE_CRC ( localCrc, (UChar)ch2 );
  515. -   
  516. +
  517.              if (ch2 != chPrev) {
  518.                 count = 1;
  519.              } else {
  520. @@ -2754,7 +2795,7 @@
  521.     }
  522.  
  523.     if (verbosity >= 2 && nBlocksRandomised > 0)
  524. -      fprintf ( stderr, "    %d block%s needed randomisation\n", 
  525. +      fprintf ( stderr, "    %d block%s needed randomisation\n",
  526.                          nBlocksRandomised,
  527.                          nBlocksRandomised == 1 ? "" : "s" );
  528.  
  529. @@ -3083,10 +3124,10 @@
  530.                     progName );
  531.     }
  532.     if (numFileNames > 0 && numFilesProcessed < numFileNames) {
  533. -      fprintf ( stderr, 
  534. +      fprintf ( stderr,
  535.                  "%s: WARNING: some files have not been processed:\n"
  536.                  "\t%d specified on command line, %d not processed yet.\n\n",
  537. -                progName, numFileNames, 
  538. +                progName, numFileNames,
  539.                            numFileNames - numFilesProcessed );
  540.     }
  541.     exit ( ec );
  542. @@ -3276,10 +3317,16 @@
  543.  /*---------------------------------------------*/
  544.  Bool fileExists ( Char* name )
  545.  {
  546. +#ifdef BZ_RISCOS
  547. +   int regs[6];
  548. +   os_file( 17, name, regs );
  549. +   return regs[0] & 1;
  550. +#else
  551.     FILE *tmp   = fopen ( name, "rb" );
  552.     Bool exists = (tmp != NULL);
  553.     if (tmp != NULL) fclose ( tmp );
  554.     return exists;
  555. +#endif
  556.  }
  557.  
  558.  
  559. @@ -3302,7 +3349,7 @@
  560.  /*---------------------------------------------*/
  561.  void copyDateAndPermissions ( Char *srcName, Char *dstName )
  562.  {
  563. -   #if BZ_UNIX
  564. +#if BZ_UNIX
  565.     IntNative      retVal;
  566.     struct MY_STAT statBuf;
  567.     struct utimbuf uTimBuf;
  568. @@ -3316,13 +3363,22 @@
  569.     ERROR_IF_NOT_ZERO ( retVal );
  570.     retVal = utime ( dstName, &uTimBuf );
  571.     ERROR_IF_NOT_ZERO ( retVal );
  572. -   #endif
  573. +#elif BZ_RISCOS
  574. +   int regs [6];
  575. +   os_file(17, srcName, regs);
  576. +   os_file(1, dstName, regs);
  577. +#endif
  578.  }
  579.  
  580.  
  581.  /*---------------------------------------------*/
  582.  Bool endsInBz2 ( Char* name )
  583.  {
  584. +#ifdef BZ_RISCOS
  585. +   int regs[6];
  586. +   os_file(17, name, regs);
  587. +   return (((regs[2] & 0x000fff00) >> 8) == BZ_FILETYPE);
  588. +#else
  589.     Int32 n = strlen ( name );
  590.     if (n <= 4) return False;
  591.     return
  592. @@ -3330,6 +3386,7 @@
  593.         name[n-3] == 'b' &&
  594.         name[n-2] == 'z' &&
  595.         name[n-1] == '2');
  596. +#endif
  597.  }
  598.  
  599.  
  600. @@ -3348,18 +3405,29 @@
  601.  {
  602.     FILE *inStr;
  603.     FILE *outStr;
  604. +   char *off;
  605.  
  606.     if (name == NULL && srcMode != SM_I2O)
  607.        panic ( "compress: bad modes\n" );
  608.  
  609.     switch (srcMode) {
  610.        case SM_I2O: strcpy ( inName, "(stdin)" );
  611. -                   strcpy ( outName, "(stdout)" ); break;
  612. +                   strcpy ( outName, "(stdout)" );
  613. +                   break;
  614.        case SM_F2F: strcpy ( inName, name );
  615.                     strcpy ( outName, name );
  616. -                   strcat ( outName, ".bz2" ); break;
  617. +#ifdef BZ_RISCOS
  618. +           off = strrchr ( outName, '.' );
  619. +           if (off == NULL) off = outName-1;
  620. +           memcpy ( off+1, "bzXXXXXX", 9);
  621. +           mktemp ( outName );
  622. +#else
  623. +                   strcat ( outName, ".bz2" );
  624. +#endif
  625. +           break;
  626.        case SM_F2O: strcpy ( inName, name );
  627. -                   strcpy ( outName, "(stdout)" ); break;
  628. +                   strcpy ( outName, "(stdout)" );
  629. +                   break;
  630.     }
  631.  
  632.     if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
  633. @@ -3377,11 +3445,13 @@
  634.                  progName, inName );
  635.        return;
  636.     }
  637. +#ifndef BZ_RISCOS
  638.     if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
  639.        fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
  640.                  progName, inName );
  641.        return;
  642.     }
  643. +#endif
  644.     if ( srcMode == SM_F2F && fileExists ( outName ) ) {
  645.        fprintf ( stderr, "%s: Output file %s already exists, skipping.\n",
  646.                  progName, outName );
  647. @@ -3455,9 +3525,19 @@
  648.     /*--- If there was an I/O error, we won't get here. ---*/
  649.     if ( srcMode == SM_F2F ) {
  650.        copyDateAndPermissions ( inName, outName );
  651. +#ifdef BZ_RISCOS
  652. +      {
  653. +         int regs[3];
  654. +         regs[2] = BZ_FILETYPE;
  655. +         os_file( 18, outName, regs);
  656. +      }
  657. +#endif
  658.        if ( !keepInputFiles ) {
  659.           IntNative retVal = remove ( inName );
  660.           ERROR_IF_NOT_ZERO ( retVal );
  661. +#ifdef BZ_RISCOS
  662. +     rename( outName, inName );
  663. +#endif
  664.        }
  665.     }
  666.  }
  667. @@ -3469,20 +3549,30 @@
  668.     FILE *inStr;
  669.     FILE *outStr;
  670.     Bool magicNumberOK;
  671. +   char *off;
  672.  
  673.     if (name == NULL && srcMode != SM_I2O)
  674.        panic ( "uncompress: bad modes\n" );
  675.  
  676.     switch (srcMode) {
  677.        case SM_I2O: strcpy ( inName, "(stdin)" );
  678. -                   strcpy ( outName, "(stdout)" ); break;
  679. +                   strcpy ( outName, "(stdout)" );
  680. +                   break;
  681.        case SM_F2F: strcpy ( inName, name );
  682.                     strcpy ( outName, name );
  683. +#ifdef BZ_RISCOS
  684. +           off = strrchr ( outName, '.' );
  685. +           if (off == NULL) off = outName-1;
  686. +           memcpy ( off+1, "bzXXXXXX", 9);
  687. +           mktemp ( outName );
  688. +#else
  689.                     if (endsInBz2 ( outName ))
  690.                        outName [ strlen ( outName ) - 4 ] = '\0';
  691. +#endif
  692.                     break;
  693.        case SM_F2O: strcpy ( inName, name );
  694. -                   strcpy ( outName, "(stdout)" ); break;
  695. +                   strcpy ( outName, "(stdout)" );
  696. +                   break;
  697.     }
  698.  
  699.     if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
  700. @@ -3501,11 +3591,13 @@
  701.                  progName, inName );
  702.        return;
  703.     }
  704. +#ifndef BZ_RISCOS
  705.     if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
  706.        fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
  707.                  progName, inName );
  708.        return;
  709.     }
  710. +#endif
  711.     if ( srcMode == SM_F2F && fileExists ( outName ) ) {
  712.        fprintf ( stderr, "%s: Output file %s already exists, skipping.\n",
  713.                  progName, outName );
  714. @@ -3576,6 +3668,14 @@
  715.              IntNative retVal = remove ( inName );
  716.              ERROR_IF_NOT_ZERO ( retVal );
  717.           }
  718. +#ifdef BZ_RISCOS
  719. +     {
  720. +        int regs[3];
  721. +        rename( outName, inName );
  722. +        regs[2] = 0xffd;
  723. +        os_file( 18, inName, regs );
  724. +     }
  725. +#endif
  726.        }
  727.     } else {
  728.        if ( srcMode == SM_F2F ) {
  729. @@ -3630,11 +3730,13 @@
  730.                  progName, inName );
  731.        return;
  732.     }
  733. +#ifndef BZ_RISCOS
  734.     if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
  735.        fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
  736.                  progName, inName );
  737.        return;
  738.     }
  739. +#endif
  740.  
  741.     switch ( srcMode ) {
  742.  
  743. @@ -3833,6 +3935,10 @@
  744.     #if DEBUG
  745.        fprintf ( stderr, "bzip2: *** compiled with debugging ON ***\n" );
  746.     #endif
  747. +
  748. +#if BZ_RISCOS
  749. +   __uname_control = __UNAME_NO_PROCESS; /* Stop Unixlib trying to mangle filenames */
  750. +#endif
  751.  
  752.     /*-- Be really really really paranoid :-) --*/
  753.     if (sizeof(Int32) != 4 || sizeof(UInt32) != 4  ||
  754.